﻿using System;
using System.ComponentModel.Composition;
using System.Data.Objects;
using Microsoft.Services.Clab.UI.Mvvmc;
using Microsoft.Services.Clab.UI.Mvvmc.Composition;

namespace Mari.SmartHotel.Modules.Foundation.Guests
{
    [ControllerExport("Modules.Foundation.Guests.SearchGuest")]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public partial class SearchGuestController
    {
        #region ViewModel reference
        public new SearchGuestViewModel ViewModel { get { return base.ViewModel as SearchGuestViewModel; } }
        #endregion

        #region Controller Initialization
        protected override IViewModel CreateViewModel()
        {
            return new SearchGuestViewModel();
        }
        #endregion

        protected override void OnInitialized()
        {
            base.OnInitialized();

            this.ViewModel.Genders = Container.Genders;
        }

        partial void SearchGuestExecuted()
        {
            ObjectParameter totalCount = new ObjectParameter("TotalCount", typeof(Int32));
            var guestListResult = Container.SearchGuest(this.ViewModel.SurnameGuest, this.ViewModel.NameGuest, this.ViewModel.GenderGuest, this.ViewModel.EmailGuest, this.ViewModel.CFGuest, this.ViewModel.PIGuest, totalCount);

            this.ViewModel.GuestListResult = guestListResult;

            this.ViewModel.TotalGuestsResult = (int)totalCount.Value;
        }

        partial void EditGuestExecuted(Mari.SmartHotel.Data.Guest initParameters)
        {
            this.Container.Detach(initParameters);
            this.ParentController.DoAction("LaunchFunctionWithParameter", "Modules.Foundation.Guests.EditGuest", initParameters);
            this.SearchGuestExecuted();
        }

        partial void CleanFieldsSearchGuestExecuted()
        {
            this.ViewModel.CFGuest = null;
            this.ViewModel.EmailGuest = null;
            this.ViewModel.GenderGuest = null;
            this.ViewModel.NameGuest = null;
            this.ViewModel.PIGuest = null;
            this.ViewModel.SurnameGuest = null;
        }
    }
}
